load("@rules_ruby//ruby:defs.bzl", "rb_library")
load("//rb/spec:tests.bzl", "rb_integration_test")

rb_library(
    name = "spec_helper",
    testonly = True,
    srcs = [
        "spec_helper.rb",
        "spec_support.rb",
    ] + glob(["spec_support/**/*"]),
    data = [
        "//rb:manager-linux",
        "//rb:manager-macos",
        "//rb:manager-windows",
    ],
    visibility = ["//rb/spec:__subpackages__"],
    deps = [
        "//rb/lib:selenium-webdriver",
        "//rb/lib/selenium:devtools",
        "//rb/lib/selenium:server",
        "//rb/lib/selenium:webdriver",
        "//rb/lib/selenium/webdriver:atoms",
        "//rb/lib/selenium/webdriver:common",
        "//rb/lib/selenium/webdriver:remote",
        "//rb/spec:rspec_matchers",
        "@bundle",
    ],
)

[
    rb_integration_test(
        name = file[:-8],
        srcs = [file],
        deps = [
            "//rb/lib/selenium/webdriver:common",
        ],
    )
    for file in glob(
        ["*_spec.rb"],
        exclude = [
            "bidi_spec.rb",
            "driver_spec.rb",
            "devtools_spec.rb",
            "element_spec.rb",
            "navigation_spec.rb",
            "network_spec.rb",
        ],
    )
]

_BIDI_FILES = [
    "bidi_spec.rb",
    "navigation_spec.rb",
    "network_spec.rb",
]

[
    rb_integration_test(
        name = f[:-8],
        srcs = [f],
        tags = ["bidi"],
        deps = [
            "//rb/lib/selenium/devtools",
            "//rb/lib/selenium/webdriver:bidi",
        ],
    )
    for f in _BIDI_FILES
]

rb_integration_test(
    name = "devtools",
    srcs = ["devtools_spec.rb"],
    tags = ["exclusive-if-local"],
    deps = [
        "//rb/lib/selenium/devtools",
        "//rb/lib/selenium/webdriver:bidi",
    ],
)

rb_integration_test(
    name = "driver",
    srcs = ["driver_spec.rb"],
)

rb_integration_test(
    name = "element",
    srcs = ["element_spec.rb"],
)
